package com.controller;

import com.model.Hccg;
import com.service.HccgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/tbXm")
public class UserController {
    @Autowired
    private HccgService hccgService;

    @RequestMapping("/view")
    public String view() {
        return "xmlx";
    }

        //添加
    @RequestMapping("/add")
    public String add1(Hccg hccg) {
        hccg.setXmStatus(1);
        hccg.setXmCreateDate(new Date());
        hccg.setXmSh1Date(new Date());
        hccgService.add(hccg);
        return "xmlx";
    }

        //查询
    @RequestMapping("/query")
    public String query(Model model, Map<String, Object> map, Hccg hccg, String startDate, String endDate){
        System.out.println("===>"+hccg.getXmName());
        map.put("XmName",hccg.getXmName());
        map.put("XmStatus",hccg.getXmStatus());
        map.put("XmImport",hccg.getXmImport());
        map.put("CreatDate",hccg.getXmCreatDate());
        if(startDate!=null && startDate.trim().length()!=0) {
            map.put("startDate",startDate + "00:00:00");
            }
        if(endDate!=null && endDate.trim().length()!=0){
            map.put("endDate",endDate+" 23:59:59");
            }
        List<Hccg> query = hccgService.query(map);

        model.addAttribute("list", query);

            return "xmcx";
    }


        //通过id查询
    @RequestMapping("/select")
    public String select(Integer id, Model model){
        Hccg select = hccgService.select(id);
        model.addAttribute("list",select);
        return "xmxg";
    }

        // 修改
    @RequestMapping("/update")
    public String update(Hccg hccg){
        hccgService.update(hccg);
        return "xmcx";
    }

        // 删除
    @RequestMapping("/delect")
    public String delect(Integer id){
        hccgService.delect(id);
        return "redirect:/tbXm/query";
    }

}

